/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.scm.rmpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import merlion.common.entity.DocFile;
import merlion.frm.bpm.entity.SupplierInvoice;

/**
 *
 * @author Kenn
 */
@Entity
public class RawMaterialSalesOrder implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private String salesOrderId;
    private Timestamp salesOrderDate;
    private Boolean currency;
    private Double total;
    @OneToOne(targetEntity = RawMaterialPurchaseOrder.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER, mappedBy = "rmso")
    private RawMaterialPurchaseOrder rmpo;
    @OneToOne(targetEntity = GoodsReceipt.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private GoodsReceipt goodsReceipt;
    @OneToOne(targetEntity = SupplierInvoice.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private SupplierInvoice invoice;
    @ManyToOne(targetEntity=Supplier.class, cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Supplier supplier;
    @OneToOne(targetEntity = DocFile.class, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
    private DocFile uploadedImage;
    @OneToMany(targetEntity=RawMaterialItemLine.class, cascade={CascadeType.PERSIST,CascadeType.MERGE}, fetch=FetchType.EAGER)
    private Collection<RawMaterialItemLine> itemlines;

    public RawMaterialSalesOrder(){
        salesOrderId = "";
        salesOrderDate = new Timestamp(System.currentTimeMillis());
        rmpo = null;
        uploadedImage = null;
        itemlines = new ArrayList<RawMaterialItemLine>();
        goodsReceipt = null;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public RawMaterialPurchaseOrder getRmpo() {
        return rmpo;
    }

    public void setRmpo(RawMaterialPurchaseOrder rmpo) {
        this.rmpo = rmpo;
    }

    public Timestamp getSalesOrderDate() {
        return salesOrderDate;
    }

    public void setSalesOrderDate(Timestamp salesOrderDate) {
        this.salesOrderDate = salesOrderDate;
    }

    public String getSalesOrderId() {
        return salesOrderId;
    }

    public void setSalesOrderId(String salesOrderId) {
        this.salesOrderId = salesOrderId;
    }

    public DocFile getUploadedImage() {
        return uploadedImage;
    }

    public void setUploadedImage(DocFile uploadedImage) {
        this.uploadedImage = uploadedImage;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    public GoodsReceipt getGoodsReceipt() {
        return goodsReceipt;
    }

    public void setGoodsReceipt(GoodsReceipt goodsReceipt) {
        this.goodsReceipt = goodsReceipt;
    }

    public Supplier getSupplier() {
        return supplier;
    }

    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    public Collection<RawMaterialItemLine> getItemlines() {
        return itemlines;
    }

    public void setItemlines(Collection<RawMaterialItemLine> itemlines) {
        this.itemlines = itemlines;
    }

    public Boolean getCurrency() {
        return currency;
    }

    public void setCurrency(Boolean currency) {
        this.currency = currency;
    }

    public Double getTotal() {
        return total;
    }

    public void setTotal(Double total) {
        this.total = total;
    }

    public SupplierInvoice getInvoice() {
        return invoice;
    }

    public void setInvoice(SupplierInvoice invoice) {
        this.invoice = invoice;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RawMaterialSalesOrder)) {
            return false;
        }
        RawMaterialSalesOrder other = (RawMaterialSalesOrder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.scm.rmpm.entity.RawMaterialSalesOrder[ id=" + id + " ]";
    }
    
}
